#!/bin/bash
set -e # fail on errors

# Redirect stderr -> stdout
exec 2>&1

<%= render("mount_point_check.erb") %>

cd <%= node['gitlab']['gitlab-pages']['dir'] %>

exec /opt/gitlab/embedded/bin/gitlab-pages \
    <% if node['gitlab']['pages-nginx']['enable'] && node['gitlab']['gitlab-pages']['listen_proxy'] %>
    -listen-proxy "<%= node['gitlab']['gitlab-pages']['listen_proxy'] %>" \
    <% end %>
    <% if node['gitlab']['gitlab-pages']['external_http'] %>
    -listen-http  "<%= node['gitlab']['gitlab-pages']['external_http'] %>" \
    <% end %>
    <% if node['gitlab']['gitlab-pages']['external_https'] %>
    -listen-https "<%= node['gitlab']['gitlab-pages']['external_https'] %>" \
    -root-cert "<%= node['gitlab']['gitlab-pages']['cert'] %>" \
    -root-key  "<%= node['gitlab']['gitlab-pages']['cert_key'] %>" \
    <% end %>
    -daemon-uid "$(id -u "<%= node['gitlab']['user']['username'] %>")" \
    -daemon-gid "$(id -g "<%= node['gitlab']['user']['username'] %>")" \
    \
    -pages-domain "<%= node['gitlab']['gitlab-pages']['domain'] %>" \
    -pages-root "<%= node['gitlab']['gitlab-pages']['pages_root'] %>" \
    \
    -redirect-http <%= node['gitlab']['gitlab-pages']['redirect_http'] %> \
    -use-http2 <%= node['gitlab']['gitlab-pages']['use_http2'] %> \
